﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Linq;
using System.Reflection;
using System.Text;
using Driver;
using Driver.Const;
using SupportLibrary;

namespace AutomationTest
{
    public class DataAccessFactory
    {
        [Import(typeof(IDataAccess))]
        private static IDataAccess _dataAccess;

        public static IDataAccess GetDataAccess()
        {
            if (_dataAccess == null)
            {
                _dataAccess = new ExcelDataAccessPlugin();

                ////An aggregate catalog that combines multiple catalogs
                //var catalog = new AggregateCatalog();
                //catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetAssembly(Driver)).Assembly);
                
                ////Create the CompositionContainer with the parts in the catalog
                //var container = new CompositionContainer(catalog);

                ////Fill the imports of this object
                //try
                //{
                //    container.ComposeParts(this);
                //}
                //catch (CompositionException compositionException)
                //{
                //    Console.WriteLine(compositionException.ToString());
                //}
            }
            return _dataAccess;
        }
    }
}
